﻿<Window x:Class="TciNewsReader_2014_04.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:infrastructure="clr-namespace:TciNewsReader_2014_04.Infrastructure"
        xmlns:behaviours="clr-namespace:TciNewsReader_2014_04.Behaviours"
        xmlns:converters="clr-namespace:TciNewsReader_2014_04.Converters"
        xmlns:customControls="clr-namespace:CustomControls;assembly=CustomControls"
        Title="{x:Static infrastructure:Constants.ApplicationTitle}" 
        Icon="Resources/Images/Identity/tyburn-geoOrb.png"
        WindowStartupLocation="Manual"
        Height="350" 
        Width="800"
        >
    <Grid>
        <customControls:BusyIndicator>
            <customControls:BusyIndicator.Style>
                <Style TargetType="customControls:BusyIndicator">
                    <Setter Property="Visibility" Value="Collapsed"/>
                    <Setter Property="StarterStopper" Value="False"/>
                    <Style.Triggers>
                        <DataTrigger Binding="{Binding IsBusy}" Value="True">
                            <Setter Property="Visibility" Value="Visible"/>
                            <Setter Property="StarterStopper" Value="True"/>
                        </DataTrigger>
                    </Style.Triggers>
                </Style>
            </customControls:BusyIndicator.Style>
        </customControls:BusyIndicator>
        <DockPanel>
            
            <DockPanel.Style>
                <Style TargetType="DockPanel">
                    <Setter Property="Visibility" Value="Visible"/>
                    <Style.Triggers>
                        <DataTrigger Binding="{Binding IsBusy}" Value="True">
                            <Setter Property="Visibility" Value="Collapsed"/>
                        </DataTrigger>
                    </Style.Triggers>
                </Style>
            </DockPanel.Style>
            <Border DockPanel.Dock="Top" BorderBrush="Navy" BorderThickness="2,0,2,0">
                <ToolBarTray DockPanel.Dock="Top" Background="Transparent" HorizontalAlignment="Stretch">
                    <ToolBarTray.Resources>
                        <Style TargetType="StackPanel">
                            <Setter Property="Width" Value="50"></Setter>
                        </Style>
                        <Style TargetType="Image">
                            <Setter Property="Height" Value="40"/>
                            <Setter Property="Width" Value="40"></Setter>
                        </Style>
                        <Style TargetType="TextBlock">
                            <Setter Property="VerticalAlignment" Value="Center"/>
                            <Setter Property="HorizontalAlignment" Value="Center"></Setter>
                            <Setter Property="Margin" Value="0"/>
                            </Style>
                        <ItemsPanelTemplate x:Key="MenuItemPanelTemplate">
                            <StackPanel Margin="-20,0,0,0" Background="White"/>
                        </ItemsPanelTemplate>
                        <Style TargetType="MenuItem">
                            <Setter Property="ItemsPanel" Value="{StaticResource MenuItemPanelTemplate}"/>
                        </Style>
                    </ToolBarTray.Resources>
                    <ToolBar Background="{StaticResource Hbrush}" HorizontalAlignment="Stretch">
                        <customControls:InterItemGap></customControls:InterItemGap>
                        <Menu>
                            <MenuItem Command="{Binding OpenIncludeExcludeCommand}" ToolTip="Select which publishers to include/exclude in the view" Foreground="Wheat">
                                <MenuItem.Header>
                                    <StackPanel >
                                        <Image Source="Resources/Images/Tango/applications-internet.png"  />
                                        <TextBlock Text="Sources" Foreground="Navy"/>
                                    </StackPanel>
                                </MenuItem.Header>
                            </MenuItem>
                        </Menu>
                        <customControls:InterItemGap></customControls:InterItemGap>
                        <Menu>
                            <MenuItem ItemsSource="{Binding SortSelectors}" ItemsPanel="{StaticResource MenuItemPanelTemplate}" ToolTip="Select how the items are sorted" Foreground="Wheat">
                                <MenuItem.Header>
                                    <StackPanel>
                                        <Image Source="Resources/Images/Tango/format-justify-left.png" />
                                        <TextBlock Text="Sort" Foreground="Navy"/>
                                    </StackPanel>
                                </MenuItem.Header>
                                <MenuItem.ItemTemplate>
                                    <DataTemplate>
                                        <MenuItem IsCheckable="True" 
                                              IsChecked="{Binding IsChecked, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}">
                                            <MenuItem.Header>
                                                <StackPanel Orientation="Horizontal">
                                                    <TextBlock Text="{Binding Description}" Foreground="Navy"/>
                                                </StackPanel>
                                            </MenuItem.Header>
                                        </MenuItem>
                                    </DataTemplate>
                                </MenuItem.ItemTemplate>
                            </MenuItem>
                        </Menu>
                        <customControls:InterItemGap/>
                        <Menu>
                            <MenuItem ItemsSource="{Binding AgeSelectors}" ItemsPanel="{StaticResource MenuItemPanelTemplate}"  ToolTip="Select which items are included/excluded in the view" Foreground="Wheat">
                                <MenuItem.Header>
                                    <StackPanel>
                                        <Image Source="Resources/Images/Tango/appointment-new.png" />
                                        <TextBlock Text="Age" Foreground="Navy"/>
                                    </StackPanel>
                                </MenuItem.Header>
                                <MenuItem.ItemTemplate>
                                    <DataTemplate>
                                        <MenuItem IsCheckable="True" 
                                              IsChecked="{Binding IsChecked, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
                                              >
                                            <MenuItem.Header>
                                                <StackPanel Orientation="Horizontal">
                                                    <TextBlock Text="{Binding Description}"/>
                                                </StackPanel>
                                            </MenuItem.Header>
                                        </MenuItem>
                                    </DataTemplate>
                                </MenuItem.ItemTemplate>
                            </MenuItem>
                        </Menu>
                        <customControls:InterItemGap/>
                        <Menu>
                            <MenuItem Command="{Binding ShowErrorsCommand}" ToolTip="See a list of problems encountered in the last refresh" Foreground="Wheat">
                                <MenuItem.Header>
                                    <StackPanel >
                                        <Image Source="Resources/Images/Tango/emblem-important.png" />
                                        <TextBlock VerticalAlignment="Center" Text="Issues"  Foreground="Navy"/>
                                    </StackPanel>
                                </MenuItem.Header>
                            </MenuItem>
                        </Menu>
                        <customControls:InterItemGap/>
                        <Menu>
                            <MenuItem Command="{Binding RefreshCommand}" ToolTip="Connect to the net and get news" Foreground="Wheat">
                                <MenuItem.Header>
                                    <StackPanel >
                                        <Image Source="Resources/Images/Tango/view-refresh.png" />
                                        <TextBlock VerticalAlignment="Center" Text="Refresh" Foreground="Navy"/>
                                    </StackPanel>
                                </MenuItem.Header>
                            </MenuItem>
                        </Menu>
                        <customControls:InterItemGap/>
                        <Menu>
                            <MenuItem Command="{Binding ShowFeedCrudCommand}" ToolTip="Create, update, or delete publishers" Foreground="Wheat">
                                <MenuItem.Header>
                                    <StackPanel >
                                        <Image Source="Resources/Images/Tango/1269850054.png" />
                                        <TextBlock VerticalAlignment="Center" Text="CRUD" Foreground="Navy"/>
                                    </StackPanel>
                                </MenuItem.Header>
                            </MenuItem>
                        </Menu>
                        <customControls:InterItemGap></customControls:InterItemGap>
                        <Menu>
                            <MenuItem Command="{Binding ShowConfigCommand}" ToolTip="Examine the application configuration" Foreground="Wheat">
                                <MenuItem.Header>
                                    <StackPanel >
                                        <Image Source="Resources/Images/Tango/applications-system.png" />
                                        <TextBlock VerticalAlignment="Center" Text="Config" Foreground="Navy"/>
                                    </StackPanel>
                                </MenuItem.Header>
                            </MenuItem>
                        </Menu>
                        <customControls:InterItemGap/>
                        <Menu>
                            <MenuItem Command="{Binding HelpAboutCommand}" ToolTip="Find out about this application"  Foreground="Wheat">
                                <MenuItem.Header>
                                    <StackPanel >
                                        <Image Source="Resources/Images/Tango/help-browser.png" />
                                        <TextBlock VerticalAlignment="Center" Text="About" Foreground="Navy"/>
                                    </StackPanel>
                                </MenuItem.Header>
                            </MenuItem>
                        </Menu>
                    </ToolBar>
                </ToolBarTray>
            </Border>
            <StatusBar DockPanel.Dock="Bottom">
                <StatusBar.Resources>
                    <Style TargetType="customControls:SbTextContainer">
                        <Setter Property="Height" Value="25"/>
                        <Setter Property="Width" Value="150"></Setter>
                    </Style>
                </StatusBar.Resources>
                <customControls:SbTextContainer Text="{Binding CountsStatus}" Foreground="Green">
                    <customControls:SbTextContainer.ToolTip>
                        <Grid>
                            <Grid.Resources>
                                <Style TargetType="TextBlock">
                                    <Setter Property="Foreground" Value="Wheat"/>
                                </Style>
                            </Grid.Resources>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition/>
                                <ColumnDefinition Width="10"/>
                                <ColumnDefinition/>
                            </Grid.ColumnDefinitions>
                            <Grid.RowDefinitions>
                                <RowDefinition/>
                                <RowDefinition/>
                                <RowDefinition/>
                                <RowDefinition/>
                                <RowDefinition/>
                                <RowDefinition/>
                            </Grid.RowDefinitions>
                            <TextBlock Grid.Column="0" Grid.Row="0" Text="Available feeds"/>
                            <TextBlock Grid.Column="2" Grid.Row="0" Text="{Binding VmStats.NumberOfFeeds}" HorizontalAlignment="Right"/>
                            <TextBlock Grid.Column="0" Grid.Row="1" Text="Active feeds"/>
                            <TextBlock Grid.Column="2" Grid.Row="1" Text="{Binding VmStats.NumberOfIncludedFeeds}" HorizontalAlignment="Right"/>
                            <TextBlock Grid.Column="0" Grid.Row="2" Text="Total items"/>
                            <TextBlock Grid.Column="2" Grid.Row="2" Text="{Binding VmStats.TotalNumberOfItems}" HorizontalAlignment="Right"/>
                            <TextBlock Grid.Column="0" Grid.Row="3" Text="Visible items"/>
                            <TextBlock Grid.Column="2" Grid.Row="3" Text="{Binding VmStats.NumberOfFilteredItems}" HorizontalAlignment="Right"/>
                            <TextBlock Grid.Column="0" Grid.Row="4" Text="Items seen"/>
                            <TextBlock Grid.Column="2" Grid.Row="4" Text="{Binding VmStats.NumberOfSeenItems}" HorizontalAlignment="Right"/>
                            <TextBlock Grid.Column="0" Grid.Row="5" Text="History items"/>
                            <TextBlock Grid.Column="2" Grid.Row="5" Text="{Binding VmStats.NumberOfHistoryItems}" HorizontalAlignment="Right"/>
                        </Grid>
                    </customControls:SbTextContainer.ToolTip>
                </customControls:SbTextContainer>
                <customControls:SbTextContainer Text="{Binding AgeStatus}" Foreground="Purple">
                    <customControls:SbTextContainer.ToolTip>
                        <Grid>
                            <Grid.Resources>
                                <Style TargetType="TextBlock">
                                    <Setter Property="Foreground" Value="Wheat"/>
                                </Style>
                            </Grid.Resources>                            
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition/>
                            <ColumnDefinition Width="10"/>
                            <ColumnDefinition/>
                        </Grid.ColumnDefinitions>
                            <TextBlock Grid.Column="0" Grid.Row="0" Text="Item age filtering"/>
                            <TextBlock Grid.Column="2" Grid.Row="0" Text="{Binding AgeStatus}"/>
                        </Grid>
                    </customControls:SbTextContainer.ToolTip>
                </customControls:SbTextContainer>
                <customControls:SbTextContainer Text="{Binding SortStatusShortName}" Foreground="DarkSlateBlue">
                    <customControls:SbTextContainer.ToolTip>
                        <Grid>
                            <Grid.Resources>
                                <Style TargetType="TextBlock">
                                    <Setter Property="Foreground" Value="Wheat"/>
                                </Style>
                            </Grid.Resources>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition/>
                                <ColumnDefinition Width="10"/>
                                <ColumnDefinition/>
                            </Grid.ColumnDefinitions>
                            <TextBlock Grid.Column="0" Grid.Row="0" Text="Sorting by"/>
                            <TextBlock Grid.Column="2" Grid.Row="0" Text="{Binding SortStatus}"/>
                        </Grid>

                    </customControls:SbTextContainer.ToolTip>
                </customControls:SbTextContainer>
                <customControls:InterItemGap/>
                <CheckBox Content="Hide read items" IsChecked="{Binding HideReadItems}"/>
                <customControls:InterItemGap/>
                <TextBlock Name="WarningTextBlock">
                    <TextBlock.Style>
                        <Style TargetType="TextBlock">
                            <Setter Property="Opacity" Value="1"/>
                            <Setter Property="Text" Value=""/>
                            <Style.Triggers>
                                <DataTrigger Binding="{Binding VmStats.NumberOfFilteredItems}" Value="0">
                                    <Setter Property="Text" Value="Nothing to show"/>
                                    <Setter Property="Foreground" Value="Red"/>
                                    <Setter Property="FontWeight" Value="Bold"/>
                                </DataTrigger>
                            </Style.Triggers>
                        </Style>
                    </TextBlock.Style>
                    <TextBlock.Triggers>
                        <EventTrigger RoutedEvent="TextBlock.Loaded">
                            <BeginStoryboard>
                                <Storyboard>
                                    <DoubleAnimation
                                        Storyboard.TargetName="WarningTextBlock"
                                        Storyboard.TargetProperty="Opacity"
                                        From="1" To="0.2" Duration="0:0:0.5"
                                        RepeatBehavior="Forever"
                                        AutoReverse="True"
                                        />
                                </Storyboard>
                            </BeginStoryboard>
                        </EventTrigger>
                    </TextBlock.Triggers>
                </TextBlock>
            </StatusBar>
            <Border DockPanel.Dock="Top" BorderBrush="Navy" BorderThickness="1">
                <Grid DockPanel.Dock="Top" >
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="3*"/>
                        <ColumnDefinition Width="15"/>
                        <ColumnDefinition Width="4*"/>
                    </Grid.ColumnDefinitions>
                    <GridSplitter Grid.Column="1" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Name="Gs1"  ToolTipService.ShowDuration="12000">
                        <GridSplitter.Background>
                            <LinearGradientBrush StartPoint="0,0" EndPoint="1,0" ColorInterpolationMode="ScRgbLinearInterpolation" SpreadMethod="Pad">
                                <GradientStop Offset="0" Color="DarkSlateBlue"/>
                                <GradientStop x:Name="GradientStop1" Offset="0.5" Color="Wheat"/>
                                <GradientStop Offset="1" Color="DarkSlateBlue"/>
                            </LinearGradientBrush>
                        </GridSplitter.Background>
                        <GridSplitter.Triggers>
                            <EventTrigger RoutedEvent="GridSplitter.MouseEnter">
                                <BeginStoryboard>
                                    <Storyboard>
                                        <ColorAnimation Storyboard.TargetName="GradientStop1"
                                                Storyboard.TargetProperty="Color"
                                                From="Wheat" To="DeepSkyBlue" 
                                                Duration="0:0:0.25"
                                                AutoReverse="True"
                                                 />
                                    </Storyboard>
                                </BeginStoryboard>
                            </EventTrigger>
                        </GridSplitter.Triggers>
                        <GridSplitter.ToolTip>
                           <ToolTip>
                            <DockPanel>
                                <DataGrid DockPanel.Dock="Top"
                                          Background="Transparent"
                                          RowBackground="Transparent"
                                          Foreground="Wheat"
                                          ItemsSource="{Binding FeedInfos}"
                                          AutoGenerateColumns="False"
                                          >
                                    <DataGrid.Columns>
                                        <DataGridTextColumn Binding="{Binding FeedPublisherName}">
                                            <DataGridTextColumn.HeaderTemplate>
                                                <DataTemplate>
                                                    <TextBlock Text="Name" Foreground="Navy"/>
                                                </DataTemplate>
                                            </DataGridTextColumn.HeaderTemplate>
                                        </DataGridTextColumn>
                                        <DataGridTextColumn Binding="{Binding ItemsCount}">
                                            <DataGridTextColumn.HeaderTemplate>
                                                <DataTemplate>
                                                    <TextBlock Text="Items" Foreground="Navy"/>
                                                </DataTemplate>
                                            </DataGridTextColumn.HeaderTemplate>
                                        </DataGridTextColumn>
                                        <DataGridTextColumn Binding="{Binding VisibleCount}">
                                            <DataGridTextColumn.HeaderTemplate>
                                                <DataTemplate>
                                                    <TextBlock Text="Visible" Foreground="Navy"/>
                                                </DataTemplate>
                                            </DataGridTextColumn.HeaderTemplate>
                                        </DataGridTextColumn>
                                        <DataGridTextColumn Binding="{Binding FilteredCount}">
                                            <DataGridTextColumn.HeaderTemplate>
                                                <DataTemplate>
                                                    <TextBlock Text="Filtered out" Foreground="Navy"/>
                                                </DataTemplate>
                                            </DataGridTextColumn.HeaderTemplate>
                                        </DataGridTextColumn>
                                    </DataGrid.Columns>
                                </DataGrid>
                            </DockPanel>
                            </ToolTip>
                        </GridSplitter.ToolTip>
                    </GridSplitter>
                    <DockPanel Grid.Column="0">
                        <ListBox 
                            behaviours:ScrollingBehaviour.ListBoxScrollingBehaviour=""
                            Background="{StaticResource CustomGradientGreenEmber}"
                            HorizontalContentAlignment="Stretch"
                            ItemsSource="{Binding ItemWrappers}"
                            SelectedItem="{Binding MasterViewSelectedItem, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}"
                            IsSynchronizedWithCurrentItem="True"
                            IsEnabled="{Binding IsReadyForInteraction}"
                            >
                            <ListBox.ItemTemplate>
                                <DataTemplate>
                                    <Border Margin="2" Padding="2" BorderBrush="Black" BorderThickness="3" Background="{Binding ItemStatus, Converter={converters:ItemStatusToColourConverter}}">
                                        <DockPanel >
                                            <DockPanel.ToolTip>
                                                <TextBlock Text="{Binding ItemPublishDate, Converter={converters:DateToTimeSpanConverter}}" Foreground="Wheat" />
                                            </DockPanel.ToolTip>
                                            <StackPanel Orientation="Horizontal" DockPanel.Dock="Top">
                                                <TextBlock Text="{Binding ItemPublishDate, Converter={converters:DateConverter}}" Foreground="Teal"/>
                                                <Rectangle Width="5"/>
                                                <TextBlock Text="{Binding FeedPublisherName, Converter={converters:Parenthesizer}}" Foreground="MediumVioletRed"/>
                                            </StackPanel>
                                            <TextBlock DockPanel.Dock="Top" Text="{Binding ItemTitle}" Foreground="Navy"  TextWrapping="Wrap"/>
                                        </DockPanel>
                                    </Border>
                                </DataTemplate>
                            </ListBox.ItemTemplate>
                        </ListBox>
                    </DockPanel>
                    <DockPanel Grid.Column="2">
                        <DockPanel DockPanel.Dock="Bottom" HorizontalAlignment="Stretch" Background="{StaticResource CustomGradientGreenEmber}">
                            <StackPanel DockPanel.Dock="Left">
                                <Button Command="{Binding OpenArticleCommand}" Width="120" ToolTip="Open a browser on this item" Foreground="Wheat">
                                    <Button.Content>
                                        <StackPanel Orientation="Horizontal">
                                            <Image Source="Resources/Images\Microsoft\j0433801.png" Height="{x:Static infrastructure:Constants.ToolbarButtonHeight}"/>
                                            <customControls:LabelItemGap/>
                                            <TextBlock Text="Open article" VerticalAlignment="Center" Foreground="Navy"/>
                                        </StackPanel>
                                    </Button.Content>
                                </Button>
                            </StackPanel>
                            <StackPanel DockPanel.Dock="Right" Orientation="Horizontal" HorizontalAlignment="Right">
                                <RepeatButton Command="{Binding GoToPreviousItemCommand}" Width="100" ToolTip="Move to the previous item" Foreground="Wheat">
                                    <RepeatButton.Content>
                                        <StackPanel Orientation="Horizontal">
                                            <Image Source="Resources\Images\Microsoft\j0432678.png" Height="{x:Static infrastructure:Constants.ToolbarButtonHeight}"/>
                                            <customControls:LabelItemGap/>
                                            <TextBlock Text="Previous" VerticalAlignment="Center" Foreground="Navy"/>
                                        </StackPanel>
                                    </RepeatButton.Content>
                                </RepeatButton>
                                <customControls:InterItemGap/>
                                <RepeatButton  Command="{Binding GoToNextItemCommand}" Width="100" ToolTip="Move to the next item" Foreground="Wheat">
                                    <RepeatButton.Content>
                                        <StackPanel Orientation="Horizontal">
                                            <TextBlock Text="Next" VerticalAlignment="Center" Foreground="Navy"/>
                                            <customControls:LabelItemGap/>
                                            <Image Source="Resources\Images\Microsoft\j0432679.png" Height="{x:Static infrastructure:Constants.ToolbarButtonHeight}"/>
                                        </StackPanel>
                                    </RepeatButton.Content>
                                </RepeatButton>
                                <customControls:InterItemGap/>
                            </StackPanel>
                        </DockPanel>
                        <customControls:TextBlockPanelHeader DockPanel.Dock="Top" Text="{Binding CurrentItemTitle}" />
                        <WebBrowser DockPanel.Dock="Top" behaviours:WebBrowserBehaviour.BindableSource="{Binding CurrentItemContent}" />
                    </DockPanel>
                </Grid>
            </Border>
        </DockPanel>
    </Grid>
</Window>
